import React from 'react'
import { BrowserRouter,Route,Routes,Navigate } from 'react-router-dom'
import {routerItem} from "../interface"
import {routes} from "./routes"

function index() {
    const marRouter=(route:routerItem[])=>{
        return route.map((v,i)=>{
            return v.path?
            <Route key={i} path={v.path} element={v.element}>
                {
                    v.children&&marRouter(v.children)
                }
            </Route>
            :<Route key={i} path={v.from} element={<Navigate to={v.to}/>}></Route>
        })
    }
    return (
        <BrowserRouter>
            <Routes>
                {
                    marRouter(routes)
                }
            </Routes>
        </BrowserRouter>
    )
}

export default index
